package com.dongbo.recorder.screenrecord.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author GuoZi
 * @date :2020/5/5 0:34
 * @description:
 */
public class DateUtils {
    public static String longToDate(long time) {
        long date = time / 1000;
        int h = (int) (date / 60 / 60);
        int m = (int) ((date - h * 60 * 60) / 60);
        int s = (int) ((date - h * 60 * 60 - m * 60) % 60);
        String hour = "";
        if (h >= 10) {
            hour = h + "";
        } else if (h > 0 && h < 10) {
            hour = "0" + h;
        } else {
            hour = "00";
        }

        String mil = "";
        if (m >= 10) {
            mil = m + "";
        } else if (m > 0 && m < 10) {
            mil = "0" + m;
        } else {
            mil = "00";
        }

        String sec = "0";
        if (s >= 10) {
            sec = s + "";
        } else if (s > 0 && s < 10) {
            sec = "0" + s;
        } else {
            sec = "00";
        }
        return hour + ":" + mil + ":" + sec;
    }

    public static String long2ymd(long timestamp) {
        // 创建SimpleDateFormat对象，用于格式化日期
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date(timestamp);
        String dateString = sdf.format(date);
        return dateString;
    }
}
